//
//  LWZZMainViewController.m
//  LWZZ_OnTheWay
//
//  Created by 罗钧友 on 16/1/26.
//  Copyright © 2016年 罗钧友. All rights reserved.
//
#import "LWZZNavView.h"
#import "LWZZFooterView.h"

#import "LWZZMainViewController.h"
#import "LWZZSTMainViewController.h"
#import "LWZZTGMainViewController.h"
#import "LWZZTNMainViewController.h"

//抽屉


#define WIDTH [UIScreen mainScreen].bounds.size.width
#define HEIGHT [UIScreen mainScreen].bounds.size.height
#define NAV_HEIGHT  100
#define FOOTER_HEIGHT 80

@interface LWZZMainViewController ()
<
UIScrollViewDelegate
>
@property (nonatomic,strong)LWZZNavView *navView;
@property (nonatomic,strong)LWZZFooterView *footerView;
@property (nonatomic,strong)UIScrollView *myView;
@property (nonatomic,strong)UIPageControl *page;

@end

@implementation LWZZMainViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self creatSubviews];
    [self creatPage];
    // Do any additional setup after loading the view.
}
-(void)creatSubviews{
    self.navView=[[LWZZNavView alloc]initWithFrame:CGRectMake(0, 0, WIDTH, NAV_HEIGHT)];
    
    self.myView=[[UIScrollView alloc]initWithFrame:CGRectMake(0, NAV_HEIGHT,WIDTH , HEIGHT-NAV_HEIGHT-FOOTER_HEIGHT)];
    self.myView.contentSize=CGSizeMake(3*WIDTH, 0);
    self.myView.pagingEnabled=YES;
    self.myView.showsHorizontalScrollIndicator=NO;
    self.myView.delegate=self;
    [self createChildViewController];
    
    self.footerView=[[LWZZFooterView alloc]initWithFrame:CGRectMake(0,HEIGHT-FOOTER_HEIGHT,WIDTH, FOOTER_HEIGHT)];
    
    [self.view addSubview:self.navView];
    [self.view addSubview: self.myView];
    [self.view addSubview:self.footerView];
    
}
-(void)createChildViewController{


    
    LWZZSTMainViewController *specialTopicVC=[[LWZZSTMainViewController alloc]init];
    specialTopicVC.view.frame=CGRectMake(0, 0, self.myView.frame.size.width,self.myView.frame.size.height );
    LWZZTGMainViewController *travelGuidesVC=[[LWZZTGMainViewController alloc]init];
    travelGuidesVC.view.frame=CGRectMake(WIDTH, 0, self.myView.frame.size.width,self.myView.frame.size.height );
    LWZZTNMainViewController *travekNotesVC=[[LWZZTNMainViewController alloc]init];
    travekNotesVC.view.frame=CGRectMake(2*WIDTH, 0, self.myView.frame.size.width,self.myView.frame.size.height );
    [self addChildViewController:specialTopicVC];
    [self addChildViewController:travelGuidesVC];
    [self addChildViewController:travekNotesVC];
    
    [self.myView addSubview:specialTopicVC.view];
    [self.myView addSubview:travelGuidesVC.view];
    [self.myView addSubview:travekNotesVC.view];
    
}
-(void)creatPage{
    self.page=[[UIPageControl alloc]initWithFrame:CGRectMake(0, 0, WIDTH, 10)];
    self.page.numberOfPages=3;
    self.page.currentPage=self.myView.contentOffset.x/WIDTH;
    //当前选中的pageControl页码
    self.page.currentPageIndicatorTintColor=[UIColor darkGrayColor];
    //为选中的pageControl页码
    self.page.pageIndicatorTintColor=[UIColor lightGrayColor];
    [self.page addTarget:self action:@selector(pageAction:) forControlEvents:UIControlEventValueChanged];
    [self.footerView addSubview:self.page];
}
-(void)pageAction:(UIPageControl *)page{
    self.myView.contentOffset=CGPointMake(self.page.currentPage*WIDTH, 0);
}
-(void)scrollViewDidScroll:(UIScrollView *)scrollView{
    self.page.currentPage=self.myView.contentOffset.x/WIDTH;
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
